Package-level declarations

Types

Link copied to clipboard
class FixedQueue<T>(val capacity: Int) : Queue<T>

A strict queue with the given capacity. The differences from java.util.ArrayDeque are:

Inherited functions

Link copied to clipboard
inline fun <T : Any> Array<*>.findIsInstance(check: (T) -> Boolean = { true }): T?
inline fun <T : Any> Iterable<*>.findIsInstance(check: (T) -> Boolean = { true }): T?
inline fun <T : Any> Iterator<*>.findIsInstance(check: (T) -> Boolean = { true }): T?
inline fun <T : Any> Sequence<*>.findIsInstance(check: (T) -> Boolean = { true }): T?

Returns the first T element that satisfies the check or null if nothing was found.

Link copied to clipboard
inline fun <T : Any> Array<*>.firstIsInstance(check: (T) -> Boolean = { true }): T
inline fun <T : Any> Iterable<*>.firstIsInstance(check: (T) -> Boolean = { true }): T
inline fun <T : Any> Iterator<*>.firstIsInstance(check: (T) -> Boolean = { true }): T
inline fun <T : Any> Sequence<*>.firstIsInstance(check: (T) -> Boolean = { true }): T

Returns the first T element that satisfies the check or throws NoSuchElementException if nothing was found.

Link copied to clipboard
fun <T : Any> Array<out T>.firstNotNull(): T

Returns the first non-null element or null otherwise.

Link copied to clipboard
inline fun <T, R : Any> Iterator<T>.firstNotNullOfOrNull(transform: (T) -> R?): R?
Link copied to clipboard
fun <T : Any> Array<out T>.firstNotNullOrNull(): T?

Returns the first non-null element or null otherwise.

Link copied to clipboard
inline fun <K, V> Map<K, *>.getAs(key: K, message: Map<K, *>.(K) -> String = { MISSING_KEY }): V

Retrieves the value associated with the specified key in the map and casts it as V. If the key is not present, throws a NoSuchElementException with the given message.

inline fun <K, V> Map<K, *>.getAs(key: K, type: Class<out V>, message: Map<K, *>.(K) -> String = { MISSING_KEY }): V
inline fun <K, V> Map<K, *>.getAs(key: K, type: KClass<out V & Any>, message: Map<K, *>.(K) -> String = { MISSING_KEY }): V

Retrieves the value associated with the specified key in the map and casts it to the provided type. If the key is not present, throws a NoSuchElementException with the given message.

Link copied to clipboard
inline fun <K, V> Map<K, *>.getAsResult(key: K, message: Map<K, *>.(K) -> String = { MISSING_KEY }): Result<V>

Retrieves the value associated with the specified key in the map, casts it as V, and wraps the result in a Result object. If the key is not present or the cast fails, the exception is encapsulated within the Result.

inline fun <K, V> Map<K, *>.getAsResult(key: K, type: Class<out V>, message: Map<K, *>.(K) -> String = { MISSING_KEY }): Result<V>
inline fun <K, V> Map<K, *>.getAsResult(key: K, type: KClass<out V & Any>, message: Map<K, *>.(K) -> String = { MISSING_KEY }): Result<V>

Retrieves the value associated with the specified key in the map, casts it to the provided type, and wraps the result in a Result object. If the key is not present or the cast fails, the exception is encapsulated within the Result.

Link copied to clipboard
inline fun <T> Array<out T>.getOrDefault(index: Int, default: T): T
inline fun BooleanArray.getOrDefault(index: Int, default: Boolean): Boolean
inline fun ByteArray.getOrDefault(index: Int, default: Byte): Byte
inline fun CharArray.getOrDefault(index: Int, default: Char): Char
inline fun DoubleArray.getOrDefault(index: Int, default: Double): Double
inline fun FloatArray.getOrDefault(index: Int, default: Float): Float
inline fun IntArray.getOrDefault(index: Int, default: Int): Int
inline fun LongArray.getOrDefault(index: Int, default: Long): Long
inline fun ShortArray.getOrDefault(index: Int, default: Short): Short
inline fun <T> List<T>.getOrDefault(index: Int, default: T): T

Returns an element at the given index or the default if the index is out of bounds.

inline fun <K, V> Map<K, V>.getOrDefault(key: K, default: V): V

Returns an element at the given key or the default if the key is not present.

Link copied to clipboard
inline fun <T> Array<out T>.getOrThrow(index: Int, message: Array<out T>.(Int) -> String): T
inline fun BooleanArray.getOrThrow(index: Int, message: BooleanArray.(Int) -> String): Boolean
inline fun ByteArray.getOrThrow(index: Int, message: ByteArray.(Int) -> String): Byte
inline fun CharArray.getOrThrow(index: Int, message: CharArray.(Int) -> String): Char
inline fun DoubleArray.getOrThrow(index: Int, message: DoubleArray.(Int) -> String): Double
inline fun FloatArray.getOrThrow(index: Int, message: FloatArray.(Int) -> String): Float
inline fun IntArray.getOrThrow(index: Int, message: IntArray.(Int) -> String): Int
inline fun LongArray.getOrThrow(index: Int, message: LongArray.(Int) -> String): Long
inline fun ShortArray.getOrThrow(index: Int, message: ShortArray.(Int) -> String): Short
inline fun <T> List<T>.getOrThrow(index: Int, message: List<T>.(Int) -> String): T

Returns an element at the given index or throws IndexOutOfBoundsException with the message if the index is out of bounds.

inline fun <K, V> Map<K, V>.getOrThrow(key: K, message: Map<K, V>.(K) -> String = { MISSING_KEY }): V

Returns an element at the given key or throws NoSuchElementException with the message if the key is not present.

Link copied to clipboard
inline fun <T> Array<out T>.getResult(index: Int): Result<T>

Returns the Result of Array.get call.

inline fun BooleanArray.getResult(index: Int): Result<Boolean>

Returns the Result of BooleanArray.get call.

inline fun ByteArray.getResult(index: Int): Result<Byte>

Returns the Result of ByteArray.get call.

inline fun CharArray.getResult(index: Int): Result<Char>

Returns the Result of CharArray.get call.

inline fun DoubleArray.getResult(index: Int): Result<Double>

Returns the Result of DoubleArray.get call.

inline fun FloatArray.getResult(index: Int): Result<Float>

Returns the Result of FloatArray.get call.

inline fun IntArray.getResult(index: Int): Result<Int>

Returns the Result of IntArray.get call.

inline fun LongArray.getResult(index: Int): Result<Long>

Returns the Result of LongArray.get call.

inline fun ShortArray.getResult(index: Int): Result<Short>

Returns the Result of ShortArray.get call.

inline fun <T> List<T>.getResult(index: Int): Result<T>

Returns the Result of List.get call.

inline fun <T> Array<out T>.getResult(index: Int, message: Array<out T>.(Int) -> String): Result<T>

Returns the Result of Array.getOrThrow call.

inline fun BooleanArray.getResult(index: Int, message: BooleanArray.(Int) -> String): Result<Boolean>

Returns the Result of BooleanArray.getOrThrow call.

inline fun ByteArray.getResult(index: Int, message: ByteArray.(Int) -> String): Result<Byte>

Returns the Result of ByteArray.getOrThrow call.

inline fun CharArray.getResult(index: Int, message: CharArray.(Int) -> String): Result<Char>

Returns the Result of CharArray.getOrThrow call.

inline fun DoubleArray.getResult(index: Int, message: DoubleArray.(Int) -> String): Result<Double>

Returns the Result of DoubleArray.getOrThrow call.

inline fun FloatArray.getResult(index: Int, message: FloatArray.(Int) -> String): Result<Float>

Returns the Result of FloatArray.getOrThrow call.

inline fun IntArray.getResult(index: Int, message: IntArray.(Int) -> String): Result<Int>

Returns the Result of IntArray.getOrThrow call.

inline fun LongArray.getResult(index: Int, message: LongArray.(Int) -> String): Result<Long>

Returns the Result of LongArray.getOrThrow call.

inline fun ShortArray.getResult(index: Int, message: ShortArray.(Int) -> String): Result<Short>

Returns the Result of ShortArray.getOrThrow call.

inline fun <T> List<T>.getResult(index: Int, message: List<T>.(Int) -> String): Result<T>

Returns the Result of List.getOrThrow call.

inline fun <K, V> Map<K, V>.getResult(key: K, message: Map<K, V>.(K) -> String = { MISSING_KEY }): Result<V>

Returns the Result of Map.getOrThrow call.

Link copied to clipboard
inline fun <T, C : Collection<T>> C.ifNotEmpty(action: C.() -> Unit): C
inline fun <K, V, M : Map<K, V>> M.ifNotEmpty(action: M.() -> Unit): M
inline fun <T> Array<out T>.ifNotEmpty(action: Array<out T>.() -> Unit): Array<out T>
inline fun ByteArray.ifNotEmpty(action: ByteArray.() -> Unit): ByteArray
inline fun CharArray.ifNotEmpty(action: CharArray.() -> Unit): CharArray
inline fun FloatArray.ifNotEmpty(action: FloatArray.() -> Unit): FloatArray
inline fun IntArray.ifNotEmpty(action: IntArray.() -> Unit): IntArray
inline fun LongArray.ifNotEmpty(action: LongArray.() -> Unit): LongArray
inline fun ShortArray.ifNotEmpty(action: ShortArray.() -> Unit): ShortArray

Applies action to the receiver if it's not empty.

Link copied to clipboard
fun <T : Any> Array<out T>.lastNotNull(): T
fun <T : Any> Iterable<T>.lastNotNull(): T
fun <T : Any> Iterator<T>.lastNotNull(): T
fun <T : Any> List<T>.lastNotNull(): T
fun <T : Any> Sequence<T>.lastNotNull(): T

Returns the last non-null element or throws NoSuchElementException otherwise.

Link copied to clipboard
inline fun <T, R : Any> Array<out T>.lastNotNullOf(transform: (T) -> R?): R
inline fun <T, R : Any> Iterable<T>.lastNotNullOf(transform: (T) -> R?): R
inline fun <T, R : Any> Iterator<T>.lastNotNullOf(transform: (T) -> R?): R
inline fun <T, R : Any> List<T>.lastNotNullOf(transform: (T) -> R?): R
inline fun <T, R : Any> Sequence<T>.lastNotNullOf(transform: (T) -> R?): R

Returns the last non-null element produced by transform function or throws NoSuchElementException otherwise.

Link copied to clipboard
inline fun <T, R : Any> Array<out T>.lastNotNullOfOrNull(transform: (T) -> R?): R?
inline fun <T, R : Any> List<T>.lastNotNullOfOrNull(transform: (T) -> R?): R?

Returns the last non-null element produced by transform function or null otherwise. The element is found by iterating the collection in reverse order.

inline fun <T, R : Any> Iterable<T>.lastNotNullOfOrNull(transform: (T) -> R?): R?
inline fun <T, R : Any> Iterator<T>.lastNotNullOfOrNull(transform: (T) -> R?): R?
inline fun <T, R : Any> Sequence<T>.lastNotNullOfOrNull(transform: (T) -> R?): R?

Returns the last non-null element produced by transform function or null otherwise. The element is found by iterating through all elements, capturing the last matching one.

Link copied to clipboard
fun <T : Any> Array<out T>.lastNotNullOrNull(): T?
fun <T : Any> List<T>.lastNotNullOrNull(): T?

Returns the last non-null element or null otherwise.

Link copied to clipboard
fun <T> Collection<T>.present(limit: Int = -1): String
fun <T> Collection<T>.present(limit: Int = -1, format: (T) -> CharSequence): String

Pretty-prints the provided collection in JSON array style.

fun <K, V> Map<K, V>.present(limit: Int = -1): String
fun <K, V> Map<K, V>.present(limit: Int = -1, format: (k: K, v: V) -> CharSequence): String

Pretty-prints the provided map in JSON dictionary style.